
var createBiquadFilter_gain_value = document.querySelector('#createBiquadFilter_gain_value');
var createBiquadFilter_gain = document.querySelector('#createBiquadFilter_gain');

var stream, audioCtx
async function _play() {
    audioCtx = new(window.AudioContext || window.webkitAudioContext)();

    stream = await navigator.mediaDevices.getUserMedia({ audio: true });


    //创建一个新的 关联 对象
    let source = audioCtx.createMediaStreamSource(stream);


    var analyser = audioCtx.createAnalyser();
    var distortion = audioCtx.createWaveShaper();//创建非线性失真效果
    var gainNode = audioCtx.createGain();//控制音频的总音量
    var biquadFilter = audioCtx.createBiquadFilter();//双二阶滤波器
    var convolver = audioCtx.createConvolver();//混合效果

  
   source.connect(analyser);
   analyser.connect(distortion);
   distortion.connect(biquadFilter);
   biquadFilter.connect(convolver);
   convolver.connect(gainNode);
   gainNode.connect(audioCtx.destination);
// biquadFilter.connect(audioCtx.destination);

    biquadFilter.type = "lowshelf";
    biquadFilter.frequency.value = 1000;//前滤波算法中以赫兹
    biquadFilter.gain.value = 25;

    createBiquadFilter_gain.oninput = function() {
        biquadFilter.gain.value = createBiquadFilter_gain.value;
        createBiquadFilter_gain_value.innerHTML=createBiquadFilter_gain.value
    }
/*
biquadFilter.type = "lowshelf";
biquadFilter.frequency.setValueAtTime(1000, audioCtx.currentTime);
biquadFilter.gain.setValueAtTime(25, audioCtx.currentTime)
*/

}




_close = () => {
    audioCtx.close()
    stream.getTracks().forEach((track) => {
        track.stop();
    });
}
